<?php

namespace Bete\Http;

use Bete\Foundation\Application;
use Bete\Exception\Exception;

class Route
{
    protected $app;

    protected $request;

    public function __construct(Application $app, Request $request)
    {
        $this->app = $app;
        $this->request = $request;
    }

    public function resolve()
    {
        $pathInfo = $this->request->pathInfo();
        $params = [];

        if ($pathInfo === '') {
            $pathInfo = 'index';
        }

        $pathInfo = trim($pathInfo, '/');
        if (strpos($pathInfo, '//') !== false) {
            throw new Exception("The request url contain double slashes.");
        }

        if (strpos($pathInfo, '/') === false) {
            $pathInfo .= '/index';
        }

        return [$pathInfo, $params];
    }

}
